@using static Lombiq.UIKit.Constants.Classes

@inject IHtmlGenerator HtmlGenerator

@{
    var viewModel = (UiKitEditorViewModel)Model.ViewModel;
    var input = viewModel.GenerateInput(HtmlGenerator, TextboxInputClass, viewModel.InputClasses);
    var hasIcon = !string.IsNullOrWhiteSpace(viewModel.IconClasses);
    var specialPlaceholder = input.Attributes.ContainsKey("placeholder") &&
                             viewModel.IsLabelEmpty() &&
                             viewModel.IsRequired();

    if (specialPlaceholder)
    {
        input.Attributes.Remove("placeholder");
    }
}

<style asp-name="@ResourceNames.LombiqUiKitEditorStyle"></style>
<script asp-name="@ResourceNames.LombiqTextBoxScript"></script>

<div id="@viewModel.GetBlockIdWithFallback()"
     class="@UiKitEditorBlockName @TextboxBlockName @viewModel.BlockClassName mb-3">
    @if (viewModel.LabelPosition != LabelPosition.Border)
    {
        @viewModel.GenerateLabel(HtmlGenerator)
    }

    @viewModel.GenerateHintBefore()

    <div class="input-group">
        @if (hasIcon)
        {
            <div class="input-group-prepend">
                <span class="input-group-text @TextboxIconContainerClass">
                    <i class="@viewModel.IconClasses @TextboxIconClass"></i>
                </span>
            </div>
        }

        @if (viewModel.LabelPosition == LabelPosition.Border)
        {
            <div class="form-floating">
                @input
                @viewModel.GenerateLabel(HtmlGenerator)
            </div>
        }
        else
        {
            @input
            @if (specialPlaceholder)
            {
                <div class="@TextboxPlaceholderClass">
                    @viewModel.Placeholder
                    <span class="@UiKitEditorRequiredAsteriskClass">*</span>
                </div>
            }
        }
    </div>

    @viewModel.GenerateHintAfter()
</div>
